var Weapon = require("Weapon");
var EnemyDamager = require("EnemyDamager");
var SFXManager = require("SFXManager");

cc.Class({
    extends: Weapon,

    properties: {
        zone: cc.Node,

        damager: EnemyDamager,

        stayTime: 0,
        hiddenTime: 0,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.setStats();

      // 暂定
      let stay = cc.tween(this.zone)
          .call(() => {
			  SFXManager.instance.playSFX(7);
              this.zone.active = true;
          })
          .to(this.stayTime, { opacity: 200 }, { easing: 'sineIn' })
          .delay(this.stayTime);

      let hidden = cc.tween(this.zone)
        .to(this.hiddenTime, { opacity: 0 }, { easing: 'sineOut' })
          .call(() => {
              this.zone.active = false;
          })
          .delay(this.hiddenTime);

      let tween = cc.tween(this.node).sequence(stay, hidden);
      cc.tween(this.node).repeatForever(tween).start();

    },

    update (dt) {

        if (this.statsUpdated == true) {
          this.statsUpdated = false;

          this.setStats();
        }


    },

  setStats() {
      this.damager.damageAmount = this.stats[this.weaponLevel].damage;

      this.damager.hitWaitTime = this.stats[this.weaponLevel].speed;

      this.zone.scale *= this.stats[this.weaponLevel].range;

      this.hiddenTime = this.stats[this.weaponLevel].timeBetweenAttacks;

      this.stayTime = this.stats[this.weaponLevel].duration;
  },
});
